package com.shopping_back.controller;


import com.shopping_back.common.Result;
import com.shopping_back.service.IDeliveryService;
import com.shopping_back.util.JwtUtils;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 物流主表 前端控制器
 * </p>
 *
 * @author Jack
 * @since 2025-07-12
 */
@RestController
@RequestMapping("/api/delivery")
@RequiredArgsConstructor
public class DeliveryController {
    private final IDeliveryService service;
    private final JwtUtils jwtUtils;

    /** 列表 */
    @GetMapping("/list")
    public Result list(@RequestParam(defaultValue="1") int page,
                       @RequestParam(defaultValue="10") int size,
                       HttpServletRequest request){
        Long uid = jwtUtils.getCurrentUserId(request);   // 登录的token？
        return Result.success(service.list(uid,page,size));
    }

    /** 详情（前端画路线拿地址） */
    @GetMapping("/{sn}")
    public Result detail(@PathVariable String sn){
        return Result.success(service.detail(sn));
    }


    /** 用户确认收货 */
    @PutMapping("/{sn}/confirm")
    public Result confirm(@PathVariable String sn){
        service.confirm(sn);
        return Result.success("确认收货成功");
    }
}
